<template>
  <view class="content">
    <view class="card">
      <view class="list">
        <view class="title">
          交班时间
        </view>
        <view class="smallText" @click="handleClick" >
          {{detailData.nowDate}}
        </view>
      </view>
    </view>
    <view class="card">
      <view class="list">
        <view class="title">
          交班人
        </view>
        <view class="smallText" @click="handleClick">
          管理员
        </view>
      </view>
    </view>
    <AddView :propsData="detailData"></AddView>
    <AtButton v-if="isAdd" type='primary' @tap="submit">交班</AtButton>
    <AtToast :isOpened="formResult.isShow" :text="formResult.showText"></AtToast>
    <AtToast :isOpened="showLoading" text="正在统计..." status="loading"></AtToast>
  </view>
</template>

<script>
import './add.scss'
import Taro from '@tarojs/taro'
import exchange from "../../api/shiftExchange.js"
import {mydateFormat } from "./../../utils/timeFormat"
import AddView from "../../components/particulars.vue"

export default {
  name: 'user',
  components: {
    AddView,
  },
  data(){
    return{
      time: "",
      dataStatus: false,
      value: "ss",
      detailData: {
        recharge_ids: "",
      }, //详细信息
      isAdd: true,
      formResult: {
        isShow:false,
        showText: ""
      },
      showLoading: false
    }
  },
  // componentWillMount () {
  //   console.log(this.$router.params) // 输出 {nextTheme: "大保健"}
  //   const { nextTheme } = this.$router.params
  //   this.setState({
  //     nextTheme
  //   })
  // }
  mounted(){
    console.log("Taro.getStorageSync('ExdetailData')", Taro.getStorageSync('ExdetailData'));
    if(Taro.getStorageSync('ExdetailData')){
      this.detailData = JSON.parse(Taro.getStorageSync('ExdetailData'));
      this.isAdd = false;
    }else{

      this.getExchange();
    }
  },
  // mounted(){
  //   // console.log("什么",Taro.getStorageSync("detail"))
  // },
  methods: {
    // changeDutySubmit
    async submit(){
      // let 
      let res = await exchange.classSetList();
      let data = {
        duty_type:2,
        room_id : Taro.getStorageSync('store_id'),
        class_id: res.data[0].id,
        class_key: 0
      }
      let exRes = await exchange.changeDutySubmit(data);
      if(exRes.code == 200){
        this.formResult.isShow = true;
        this.formResult.showText = exRes.msg;
        setTimeout(()=> {
          Taro.redirectTo({
            url: "/pages/shiftExchange/list"
          });
        },400);
      }
    },
    async getExchange(){
      this.showLoading = true
      var data = {
        duty_type:2,
        room_id : Taro.getStorageSync('store_id')
      }
      let res = await exchange.changeDutySubmit(data);
      console.log("jio班详情", res);
      this.showLoading = false;
      if(res.code == 200){
          console.log(res.data);
          this.detailData = Object.assign(res.data);
          this.detailData.gasoli_discount = this.detailData.gasoli_order_money == '0'? '0':(Number(this.detailData.gasoli_order_money) - Number(this.detailData.gasoli_amount)).toFixed(2)
          this.detailData.diesel_discount = this.detailData.diesel_order_money == '0'? '0':(Number(this.detailData.diesel_order_money) - Number(this.detailData.diesel_amount)).toFixed(2)
          if(this.detailData.begintime == 1){
            this.detailData.nowDate = "首次收款" + " ~ " + mydateFormat(Number(this.detailData.endtime));
          }else{
            this.detailData.nowDate = mydateFormat(Number(this.detailData.begintime)) + " ~ " + mydateFormat(Number(this.detailData.endtime));
          }
          // this.formData.amount = (Number(res.data.cash) + Number(res.data.ex_cash_amount)).toFixed(2);
          // this.formData.pretty_cash = res.data.pretty_cash;
          this.detailData.show_recharge_unionpay_amount = (Number(res.data.ex_unionpay_amount) + Number(res.data.ex_wechat_pay_amount)).toFixed(2);
          this.detailData.show_order_unionpay_amount = (Number(res.data.wechat_pay) - Number(res.data.ex_wechat_pay_amount) + Number(res.data.consume_unionpay_amount)).toFixed(2);
          this.detailData.show_unionpay_total = (Number(res.data.unionpay_amount) + Number(res.data.wechat_pay)).toFixed(2);
          this.detailData.show_all_recharge = (Number(res.data.oil_card_money) + Number(res.data.family_card_money) + Number(res.data.car_card_money) + Number(res.data.balance)).toFixed(2)
          console.log("shuju zuihou ", this.detailData);
        }else{
          // this.$message({
          //   type: "error",
          //   message: res.msg
          // })
        }
    },
    handleClick(){
      this.dataStatus = true;
      console.log("111");
    },
    changeContent(a){
      console.log("数据", a);
    },
    goTo(item){
      Taro.navigateTo({
        url: item.path
      })
      console.log("数据", item.path)
    },
  }
}

</script>
